var path = require('path')
var fs = require('fs')
var format = path.sep


function deleteall(path) {
  var files = [];
  try {
    if (fs.existsSync(path)) {
      if (fs.statSync(path).isDirectory()) {
        files = fs.readdirSync(path);
        files.forEach(function (file, index) {
          var curPath = path + format + file;
          if (fs.statSync(curPath).isDirectory()) { // recurse
            deleteall(curPath);
          } else { // delete file
            fs.unlinkSync(curPath);
          }
        });
        fs.rmdirSync(path);
      } else {
        fs.unlinkSync(path)
      }

    }

  } catch (e) {
    console.log(e);
  }
}


module.exports.format = format
module.exports.deleteall = deleteall
